﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using System.Data;
using University.Workshop.Business;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for RateDataAccessTest and is intended
    ///to contain all RateDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RateDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for InsertRate
        ///</summary>
        [TestMethod()]
        public void InsertRateTest()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            string aleatorio = random.Next(10000).ToString();

            Rate rate = RateManager.RegisterNewRate(
                    "101"+aleatorio,
                    "Servicio"+aleatorio,
                    "12",
                    "descripcion"
                );

            Rate expected = rate; // TODO: Initialize to an appropriate value
            Rate actual;
            actual = RateDataAccess.InsertRate(rate);
            Assert.AreEqual(expected, actual);

        }

        [TestMethod()]
        public void InsertRateTestFail()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            string aleatorio = random.Next(10000).ToString();

            Rate rate = null;

            Rate expected = null; // TODO: Initialize to an appropriate value
            Rate actual;
            actual = RateDataAccess.InsertRate(rate);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for DeleteRate
        ///</summary>
        [TestMethod()]
        public void DeleteRateTest()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            string aleatorio = random.Next(10000).ToString();

            Rate rate = RateManager.RegisterNewRate(
                    "101" + aleatorio,
                    "Servicio" + aleatorio,
                    "12",
                    "descripcion"
                );
            bool expected = true;
            RateDataAccess.InsertRate(rate);
            bool actual = RateDataAccess.DeleteRate(rate.Code);
            Assert.AreEqual(expected, actual);
  
        }

        [TestMethod()]
        public void DeleteRateTestFail()
        {
            bool actual = RateDataAccess.DeleteRate(null);
            Assert.AreEqual(false, actual);
        }

        /// <summary>
        ///A test for GetRates
        ///</summary>
        [TestMethod()]
        public void GetRatesTest()
        {
            DataTable actual;
            actual = RateDataAccess.ShowRates();
            Assert.IsNotNull(actual);

        }

        /// <summary>
        ///A test for UpdateRate
        ///</summary>
        [TestMethod()]
        public void UpdateRateTest()
        {
            Rate rate = RateManager.RegisterNewRate(
                    "123",
                    "Servicio modificado",
                    "20",
                    "descripcion modificada"
                );
            bool expected = true;
            bool actual;
            actual = RateDataAccess.UpdateRate(rate);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void UpdateRateTestFail()
        {

            bool expected = false;
            bool actual;
            actual = RateDataAccess.UpdateRate(null);
            Assert.AreEqual(expected, actual);
        }
    }
}
